/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oop.example.work.esport;

import com.oop.example.processing.EntryDisplay;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * @author -
 */
public class Esp2PortEntryDisplay extends EntryDisplay {

    String commonChars = "[= a-zA-Z0-9-\\:\\'\\.\\;\"\\,]*";
    Map<String, String> replacements = new LinkedHashMap<String, String>();

    public Esp2PortEntryDisplay() {
        replacements.put("<b><span (class|style|lang)=" + commonChars + "color:aqua" + commonChars + ">", "<TEMPB style='color:aqua'>");
        replacements.put("<p class=" + commonChars + ">", "<p>");
        replacements.put("<b (style|lang)=" + commonChars + ">", "<b>");
        replacements.put("<span (class|style|lang)=" + commonChars + ">", "<span>");
        replacements.put("<i (style|lang)=" + commonChars + ">", "<i>");
    }

    private String clean(String string) {
        boolean exit = false;
        while (!exit) {
            exit = true;
            for (String key : replacements.keySet()) {
                if (string.matches(".*" + key + ".*")) {
                    string = string.replaceAll(key, replacements.get(key));
                    exit = false;
                    break;
                }
            }
        }
        return string;
    }

    @Override
    public String preProcess(String src) {
        String content = clean(src);
        content = content.replaceAll("color:aqua", "color:blue");
        content = content.replaceAll("<TEMPB style='color:blue'>", "<b style='color:blue'>");
        //System.out.println(content);
        return content;
    }

    @Override
    public String postProcess(String src) {
//        String from = "<body bgcolor=";
//        String to = "<body style=\"font-size:18pt;\" bgcolor=";
//        src = src.replace(from, to);
        return src;
    }
}
